<template>
	<view class="container">
		<cu-custom bgColor="bg-gray" :isBack="true">
			<block slot="content">我的签到</block>
		</cu-custom>

		<view class="containerBox">
			<u-sticky offset-top="58">
				<view class="padding-tb-xs bg-gray">
					<view class="tabs flex justify-center align-center">
						<view class="tabItem " :class="info_type==1?'change':''" @click="changeType(1)">
							我创建的
						</view>
						<view class="tabItem" :class="info_type==2?'change':''"   @click="changeType(2)">
							我参与过
						</view>
					</view>
				</view>
			</u-sticky>
			<view class="margin-top-xs" v-for="(item,index) in goodsList" :key="index" @click.stop="navTo(`/pages/signDetail/index?id=${item.id}&edit=false`)">
				<view class="cellBox margin-top-lg">
					<u-cell-group  :border="false">
					    <u-cell :title="item.title" :label="item.date" isLink :border="false" >
					    	<view slot="value" class="u-slot-value"></view>
					    </u-cell>
					</u-cell-group>
				</view>
			</view>
			<uni-load-more :status="loadingType"></uni-load-more>
		</view>	
	</view>
</template>
<script>
	import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
	export default {
		components: {
			uniLoadMore	
		},
		data() {
			return {
				loadingType: 'more', //加载更多状态
				cateList: [],
				goodsList: [],
				pageindex:1,
				info_type:1,
				type:"",
				checkId:[],
			};
		},
		onLoad(options){
			this.loadData('refresh');
			
		},
		//下拉刷新
		onPullDownRefresh(){
			this.loadData('refresh');
		},
		//加载更多
		onReachBottom(){
			this.loadData();
		},
		methods: {
			navTo(url) {
				uni.navigateTo({
					url: url
				})
			},
			changeType(type){
				this.info_type = type;
				this.loadData('refresh');
			},
			//加载列表
			async loadData(type='add',loading) {
				let _this = this;
				//没有更多直接返回
				if(type === 'add'){
					if(this.loadingType === 'nomore'){
						return;
					}
					this.loadingType = 'loading';
				}else{
					this.loadingType = 'more'
				}
				if(type === 'refresh'){
					this.pageindex = 1;
				}
				this.$ComFunJS.ajax({
					method:"get",
					url:this.info_type==1?"/rest/api/myCreateList":"/rest/api/myJoinList",
					data:{
						page:this.pageindex
					},
					success:(res)=>{
						if(res.code==0){
							let goodsList = res.data;
							if(type === 'refresh'){
								_this.goodsList = [];
							}
							if(goodsList.length>0){
								_this.pageindex++
							}	
							_this.goodsList = _this.goodsList.concat(goodsList);
							//判断是否还有下一页，有是more  没有是nomore(测试数据判断大于20就没有了)
							_this.loadingType  =res.data.length &&res.data.length >=10 ? 'more' : 'nomore';
							if(type === 'refresh'){
								if(loading == 1){
									uni.hideLoading()
								}else{
									uni.stopPullDownRefresh();
								}
							}							
						}
					}
				})
			},
		},
	}
</script>

<style lang='scss'>
.containerBox{
	padding: 32upx;
}
.tabs{
	.tabItem{
		font-size: 32upx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		position: relative;
		&.change{
			color: #1A75FF;
			&::after{
				content: "";
				width: 124upx;
				height: 6upx;
				background: #1A75FF;
				border-radius: 20upx;
				position: absolute;
				bottom: -12upx;
				left: 0;
			}
		}
		&:nth-child(1){
			margin-right: 54upx;
		}
	}
}
.cellBox{
	border-radius: 20upx;
	background: #fff;
}
</style>
